//
//  ZLPResultDetailTableViewCell.m
//  TangYi
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 赵连鹏. All rights reserved.
//

#import "ZLPResultDetailTableViewCell.h"

@implementation ZLPResultDetailTableViewCell

- (void)dealloc {
    [_titleLabel release];
    [_descLabel release];
    [_picImageView release];
    [_priceLabel release];
    [_button release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:19];
    [_titleLabel release];
    
    self.descLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.descLabel];
    self.descLabel.textColor = [UIColor grayColor];
    self.descLabel.numberOfLines = 0;
    self.descLabel.font = [UIFont systemFontOfSize:16];
    [_descLabel release];
    
    self.picImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.picImageView];
    [_picImageView release];
    
    self.priceLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.priceLabel];
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.font = [UIFont systemFontOfSize:20];
    self.priceLabel.textAlignment = NSTextAlignmentLeft;
    [_priceLabel release];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.button];
    [self.button setTitle:@"购买" forState:UIControlStateNormal];
    [self.button setImage:[UIImage imageNamed:@"shopping.png"] forState:UIControlStateNormal];
    self.button.backgroundColor = [UIColor redColor];
    self.button.layer.cornerRadius = 15;
    self.button.layer.masksToBounds = YES;
    [self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(5, 0, self.contentView.frame.size.width - 10, 30);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    
    CGRect rect = [self.descLabel.text boundingRectWithSize:CGSizeMake(375, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.descLabel.frame = CGRectMake(5, 30, self.contentView.frame.size.width - 10, rect.size.height + 20);
    self.picImageView.frame = CGRectMake(5, rect.size.height + 50, self.contentView.frame.size.width - 10, 370);
    self.priceLabel.frame = CGRectMake(5, rect.size.height + 425, 250, 30);
    self.button.frame = CGRectMake(self.contentView.frame.size.width - 115, rect.size.height + 425, 100, 30);
}

- (void)click:(UIButton *)button {
    [self.delegate click];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
